package com.clubs.coding.common;

import com.clubs.coding.exception.ImoocMallException;
import com.clubs.coding.exception.ImoocMallExceptionEnum;
//import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/*
* 常量类
* */
//因为要使用@Value完成自动的注入所以需要@Component
@Component
public class Constant {
    public static final String SALT ="asfFAG174*-/=";//MD5盐值
//    public static final String MY_BBS ="my_bbs";//session key
    public static final String NULL ="NULL";
    public static String FILE_UPLOAD_DIR;
    public static String FILE_DOWNLOAD_DIR;
    public static final String PAGE_SIZE="10";
    public static final String NEED_LOGIN="用户未登录";
    public static final String appid="wx9c3d61e786f8245d";
    public static final String AppSecret="c105fc82fc62fb7fca80a95caa648e17";
    public static final String ATH_CLUBS_USER ="ath_clubs_user";//session key
    @Value("${file.upload.dir}")
    public void setFileUploadDir(String fileUploadDir) {
        FILE_UPLOAD_DIR = fileUploadDir;
    }
    @Value("${file.download.dir}")
    public void setFileDownloadDir(String fileUploadDir) {
        FILE_DOWNLOAD_DIR = fileUploadDir;
    }
    //枚举
//    public interface ProductListOrderBy {
//        Set<String> PRICE_ASE_DESC = Sets.newHashSet("price desc","price asc");
//    }
    //上下架枚举
    public interface SaleStatus {
       int NOT_SALE=0;//商品下架状态
        int SALE=1;//上架
    }
    //购物车是否选中枚举
    public interface Cart {
        int UN_CHECKED=0;//未选中
        int CHECKED=1;//选中
    }
    public enum OrderStatusEnum {
        CANCELED(0, "用户已取消"),
        NOT_PAID(10, "未付款"),
        PAID(20, "已付款"),
        DELIVERED(30, "已发货"),
        FINISHED(40, "交易完成");

        private String value;
        private int code;

        OrderStatusEnum(int code, String value) {
            this.value = value;
            this.code = code;
        }

        public static OrderStatusEnum codeOf(int code) {
            for (OrderStatusEnum orderStatusEnum : values()) {
                if (orderStatusEnum.getCode() == code) {
                    return orderStatusEnum;
                }
            }
            throw new ImoocMallException(ImoocMallExceptionEnum.NO_ENUM);
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }
}
